package com.nuoniu.sibanyun.controller.user;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.user.SysUserBank;
import com.nuoniu.sibanyun.service.user.ISysUserBankService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户银行卡管理
 * @author 小啊刚
 * @since 2020-09-03
 */
@RestController
@RequestMapping("/user/bank")
@Api(tags = "用户银行卡管理", value = "用户银行卡管理")
public class SysUserBankController extends BaseController {

    @Autowired
    private ISysUserBankService bankService;

    /**
     * 银行卡列表
     * @author 小啊刚
     * @date 2020-09-03
     */
    @GetMapping("pageList")
    public HttpResult pageList(Page page, SysUserBank bank) {
        return HttpResult.ok(bankService.pageList(page, bank));
    }

    /**
     * 保存银行卡
     * @author 小啊刚
     * @date 2020-09-03
     */
    @PostMapping("save")
    public HttpResult save(@RequestBody SysUserBank userBank) {
        UserInfo userInfo = UserThreadLocal.get();
        userBank.setUserId(userInfo.getUserId());
        bankService.saveOrUpdate(userBank);
        return HttpResult.ok();
    }

    /**
     * 删除银行卡
     * @author 小啊刚
     * @date 2020-09-03
     */
    @PostMapping("delete")
    public HttpResult delete(@RequestBody List<String> ids) {
        for(String id : ids) {
            bankService.removeById(id);
        }
        return HttpResult.ok();
    }
}
